#include"stack.h"



void test()
{
    char* a = (char*)malloc(sizeof(char) * 105);
    memset(a,'\0', sizeof(char) * 105);
    stack p1;
    while (gets(a) != NULL)
    {
        printf("%s\n", a);
        int i = 0, j=0;
        char count = '0';
        InitStack(&p1);
        while (a[j] != '\0')
        {
            if (a[j] == '(')
            {
                count = j + '0';
                a[j] = count;
                pushStack(&p1, count);
            }
            else if (a[j] >= 'A' && a[j] <= 'Z' || a[j] >= 'a' && a[j] <= 'z')
            {
                a[j] = ' ';
            }
            else if (a[j] == ')')
            {
                if (!StackEmpty(&p1))
                {
                    char n=StackTop(&p1);
                    int m = n - '0';
                    a[m] = ' ';
                    popStack(&p1);
                    a[j] = ' ';
                }
                else
                {
                    a[j] = '?';
                }
            }
            j++;
        }
        while (!StackEmpty(&p1))
        {
            char n = StackTop(&p1);
            int m = n - '0';
            a[m] = '$';
            popStack(&p1);
        }
        printf("%s\n", a);
        StackDestroy(&p1);
    }
}
int main()
{
    test();
    return 0;
}